﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBE.Services;
using CBE.Model;
using Common.UI.EM.Views;
using Common.UI.EM.Views.Interfaces;
using Microsoft.Practices.Composite.Presentation.Commands;
using System.Windows;

namespace CBE.UI.Control
{
    public partial class AdministrarVentasEntityPresentationModel : EntityPresentationModel<AdministrarVentasServiceLogic, Ventas, AdministrarVentasCriteria, AdministrarVentasView>
    {

        public AdministrarVentasEntityPresentationModel(IFilterView filterView, IListView listView, IDetailView detailView)
            : base(filterView, listView, detailView)
        {
        }

        #region Detail
        public event EventHandler ClienteNuevoCalled;

        public DelegateCommand<Object> ClienteNuevoCommand
        {
            get;
            set;
        }

        protected override void AddDetailCustomCommands()
        {
            this.ClienteNuevoCommand = new DelegateCommand<object>(ExecuteClienteNuevoCommand, CanExecuteClienteNuevoCommand);
        }

        void ExecuteClienteNuevoCommand(Object args)
        {
            if (ClienteNuevoCalled != null)
            {
                ClienteNuevoCalled(this, new EventArgs());
            }
        }

        Boolean CanExecuteClienteNuevoCommand(Object args)
        {
            return true;
        }
        #endregion

        #region List
        public AdministrarVentasServiceLogic AdministrarVentasService
        {
            get { return (AdministrarVentasServiceLogic)this.EntityManager; }
        }

        public override string DeleteLabel
        {
            get
            {
                return "Anular";
            }
        }

        protected override bool ValidateOnDelete()
        {
            if (MessageBox.Show("¿Está seguro que desea anular la venta?", "Confirmación", MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return false;
            }
            return true;
        }

        protected override void DeleteEntity()
        {
            AdministrarVentasService.Cancelar(this.SelectedEntity);
        }
        #endregion

    }
}
